<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<ul id="riskTab" class="contListTab mt10">
    <li onclick="javascript:$('#productCategoriesMenu').click();" class="selectContListTab"><a href="javascript:void(0);">Create Categories</a></li>
	<li onclick="javascript:$('#productCategoryLevel0').click();"><a href="javascript:void(0);">Categories List</a></li>
</ul>
<div id="riskTabCnt">
	<div class="pad10">
        <input type="hidden" id="categoryId"/>
        <ul class="mode_add">
            <li id="categoryLevelMenu">
                <label>Category Level:</label>
                Level 1 <input type="radio" checked="checked" value="0" name="categoryLevel" id="categoryLevel"/>&nbsp;&nbsp;&nbsp;&nbsp;
                Level 2 <input type="radio" value="1" name="categoryLevel" id="categoryLevel"/>
            </li>
            <li id="rootCategory" style="display: none;">
                <label>Root Categories:</label>
                <select id="rootCategories" name="parentId" style="width: 150px;height: 20px;">
                </select>
            </li>
			<li>
			    <label>Subject:</label>
			    <input type="text" id="subject" name="subject" class="input_txt" size="60" maxlength="100"/>
			</li>
			<li>
			    <label>Description:</label>
			    <textarea class="input_tex" id="description" name="description" style="width:358px;height:100px;"></textarea>
			</li>
            <li class="wrap_flow" id="categoryForm">
                <label style="float:left">Image:</label>
                <div style="padding-left: 118px;">
	                <form method="POST" enctype="multipart/form-data" id="productCategoryImageForm" style="float:left;"> 
	                    <input type="hidden" name="filePath" value="file/productCategory"/>
	                    <input type="hidden" name="width" value="160"/>
	                    <input type="hidden" name="height" value="118"/>
	                    <input type="file" name="file" id="file" onchange="javascript:$('#productCategoryImageForm').submit();"/>
	                </form>
                    <font style="float:left;" color="red">Image Size: 160 x 118</font>
                </div>
                <input type="hidden" id="productCategoryFilePath"/>
			</li>
			<li id="categoryImage">
			    <label>Image Preview:</label>
			    <img style="width:160px;height:118px;" id="productCategoryImage">
			</li>
			<li>
			    <label>&nbsp;</label>
			    <input type="button" id="createProductCategoryButton" value="Add" class="blueBtn" />
			</li>
		</ul>
	</div>
	
	<!-- Categories List -->
    <div class="pad10" style="display: none;">
        <ul class="mode_add">
            <li>
                <label>Category Level:</label>
                Level 1 <input type="radio" checked="checked" value="0" name="productCategoryLevel" id="productCategoryLevel0" onclick="javascript:product.categoriesListByParentId(0,1,'categoriesList');"/>&nbsp;&nbsp;&nbsp;&nbsp;
                Level 2 <input type="radio" value="1" name="productCategoryLevel" id="productCategoryLevel1"/>
            </li>
            <li id="rootCategoryLi" style="display:none;">
                <label>Root Category:</label>
                <select id="rootCategoryId" name="rootCategoryId" style="width: 150px;height: 20px;">
                </select>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="button" onclick="javascript:product.currentRootCategoryId=$('#rootCategoryId').val();product.categoriesListByParentId($('#rootCategoryId').val(),1,'categoriesList');" value="Query" class="blueBtn" />
            </li>
        </ul>
        <table class="listTable tac mar10">
            <thead>
                <tr>
                    <th>Subject</th>
                    <th>Description</th>
                    <th>Parent Category</th>
                    <th>Create Date</th>
                    <th>Operition</th>
                </tr>
            </thead>
            <tbody id="categoriesList">
            </tbody>
        </table>
    </div>
</div>

<script type="text/javascript" src="js/product.js"></script>
<script type="text/javascript">
	//切换
	switchTab("riskTab","riskTabCnt","div","selectContListTab");
    
	$("input[name='categoryLevel']").change(function() { 
		var levelValue = $(this).val(); 
		if(levelValue==1){
		    product.categoriesListByParentId(0,0,'rootCategories');
		    
			$('#rootCategory').show();
			$('#categoryForm').hide();
			$('#categoryImage').hide();
		}else{
			$('#productCategoryFilePath').val("");
			$('#productCategoryImageForm').resetForm();
			$('#productCategoryImage').attr('src','');
			
			$('#rootCategory').hide();
			$('#categoryForm').show();
			$('#categoryImage').show();
		}
	});
	
	$("input[name='productCategoryLevel']").change(function() { 
		var levelValue = $(this).val(); 
		if(levelValue==1){
            $('#categoriesList').html("");
            
		    product.categoriesListByParentId(0,0,'rootCategoryId');

            $('#rootCategoryLi').show();
		}else{
			$('#rootCategoryLi').hide();
		}
	});
    
    upload.uploadImage('productCategory');

    var categoryId = '<%=request.getParameter("categoryId")%>';
    var parentId = '<%=request.getParameter("parentId")%>';
    if(categoryId!=null&&categoryId!='null'&&parentId!=null&&parentId!='null'){
        $('#categoryLevelMenu').hide();
        if(parentId==0){
            $('#rootCategory').hide();
            $('#categoryForm').show();
            $('#categoryImage').show();
            $("input[name='categoryLevel'][value='0']").attr("checked","checked");
        }else{
            $('#rootCategory').show();
            $('#categoryForm').hide();
            $('#categoryImage').hide();
            $("input[name='categoryLevel'][value='1']").attr("checked","checked");
        }
        product.modifyProductCategory(categoryId);
        product.categoriesListByParentId(0,0,'rootCategories',parentId);
        $('#createProductCategoryButton').click(function(){
        	product.createCategory('update');
        });
    }else{
        product.categoriesListByParentId(0,0,'rootCategories');
        $('#createProductCategoryButton').click(function(){
        	product.createCategory('create');
        });
    }
</script>
